package org.yn.subject.domain.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import org.yn.subject.domain.convert.SubjectCategoryConverter;
import org.yn.subject.domain.dto.SubjectCategoryDTO;
import org.yn.subject.domain.entity.SubjectCategoryBO;
import org.yn.subject.domain.service.SubjectCategoryDomainService;
import org.yn.subject.infra.basic.entity.SubjectCategory;
import org.yn.subject.infra.basic.service.SubjectCategoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Service
public class SubjectCategoryDomainServiceImpl implements SubjectCategoryDomainService {

  @Resource
  private SubjectCategoryService subjectCategoryService;
  @Resource
  private SubjectCategoryConverter subjectCategoryConverter;

  @Override
  public void add(SubjectCategoryBO subjectCategoryBO) {

    SubjectCategory subjectCategory= subjectCategoryConverter.toSubjectCategory(subjectCategoryBO);
    subjectCategoryService.save(subjectCategory);
  }

  @Override
  public Object page(Page<SubjectCategory> page,
      QueryWrapper<SubjectCategory> subjectCategoryQueryWrapper) {
    return null;
  }

  @Override
  public SubjectCategoryDTO getById(Serializable id) {
    SubjectCategory subjectCategory = subjectCategoryService.getById(id);
    return subjectCategoryConverter.toSubjectCategoryDTO(subjectCategory);
  }

  @Override
  public Boolean save(SubjectCategoryBO subjectCategoryBO) {
    SubjectCategory subjectCategory= subjectCategoryConverter.toSubjectCategory(subjectCategoryBO);
    subjectCategory.setCreatedTime(new Date());
    return subjectCategoryService.save(subjectCategory);
  }

  @Override
  public Boolean updateById(SubjectCategoryBO subjectCategoryBO) {
    SubjectCategory subjectCategory= subjectCategoryConverter.toSubjectCategory(subjectCategoryBO);
    subjectCategory.setUpdateTime(new Date());
    return subjectCategoryService.updateById(subjectCategory);
  }

  @Override
  public Boolean removeByIds(List<Long> idList) {
    return subjectCategoryService.removeByIds(idList);
  }

  @Override
  public List<SubjectCategoryBO> queryPrimaryCategory(Long parentId) {
  List<SubjectCategory> subjectCategoryList= subjectCategoryService.queryPrimaryCategory(parentId);
    return subjectCategoryConverter.toSubjectCategoryBO(subjectCategoryList);
  }
}
